package com.summer.safe.config.result;

/**
 * 统一消息返回
 *
 */

public class ResultWrapperEntity<T> {

    /**
     * 成功状态码
     */
    public static final String CODE_SUCCESS = "0";
    /**
     * 失败状态码
     */
    public static final String CODE_ERROR = "1";

    /**
     * 返回的消息
     */
    private String code;
    /**
     * 返回的消息
     */
    private String msg;
    /**
     * 返回值，类型为T
     */
    private T data;

    /**
     * 数据总数
     */
    private long count;

    public ResultWrapperEntity(T data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.data = data;
    }

    public ResultWrapperEntity() {

    }


    /**
     * 返回成功消息
     *
     * @param msg 返回内容
     * @return 成功消息
     */
    public static ResultWrapperEntity success(String msg) {
        return new ResultWrapperEntity(CODE_SUCCESS,msg);
    }
    /**
     * 返回失败消息
     *
     * @param msg 返回内容
     * @return 成功消息
     */
    public  static ResultWrapperEntity error(String msg) {
        return new ResultWrapperEntity(CODE_ERROR,msg);
    }



    public ResultWrapperEntity(String cod,String msg) {
        this.code = cod;
        this.msg = msg;
    }


    public ResultWrapperEntity(ResultCode returnCode) {
        this.code = returnCode.getCode();
        this.msg =returnCode.getMsg();
    }

    public ResultWrapperEntity(ResultCode returnCode, T data) {
        this.code = returnCode.getCode();
        this.msg = returnCode.getMsg();
        this.data = data;
    }

    public ResultWrapperEntity(ResultCode returnCode, T data, long count) {
        this.code = returnCode.getCode();
        this.msg = returnCode.getMsg();
        this.data = data;
        this.count = count;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }
}
